package ZombieCaminando;

import java.util.ArrayList;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

public class Juego  extends Thread {

	protected ArrayList<Zombie> Zombies;
	protected Ventana ventana;
	protected TimerTask timerTask;
	protected boolean perdio;
	protected Random random;

	public Juego(Ventana vent) {             
		Zombies = new ArrayList<Zombie>();
		ventana =vent;
		perdio= true;
		random=new Random();
		start();
		timerTask=new TimerTask() {


			public void run() {

				int posy=(int)(random.nextDouble()*5);				
				inicializarEntidades(posy);
			}
		};
		Timer timer=new Timer();
		timer.scheduleAtFixedRate(timerTask, 100, 4000);
	}



	private void inicializarEntidades(int posy) {

		Zombi z = new Zombi(1030,posy*100,this);
		Zombies.add(z);
		z.start();              
	}
	
	private void juegoFinalizado() {

	}

	public void run() {
		boolean aux = true;
		while(aux){
			try {
				sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if(!perdio){
				aux=false;
				timerTask.cancel();
				ventana.perdio();
			}}


	}

	public Ventana getVentana(){
		return ventana;
	}


	private void reiniciarJuego() {

	}
	public void yaPerdio(){
		perdio = false;	 
	}

	public boolean getPerdio(){
		return perdio;
	}

}

